//
//  HeartVideoCollectionViewCell.m
//  miaopai
//
//  Created by duyifang on 15/11/24.
//  Copyright © 2015年 Crow Zhang. All rights reserved.
//

#import "HeartVideoCollectionViewCell.h"
#import "AutoadaptationFrame.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface HeartVideoCollectionViewCell ()

@property(nonatomic, retain) UIImageView *pictureImageView;

@property(nonatomic, retain) UILabel *introduceWordsLabel;

@end

@implementation HeartVideoCollectionViewCell

- (void)dealloc
{
    [_pictureImageView release];
    [_introduceWordsLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self creatSubViews];
    }
    return self;
}

- (void)creatSubViews
{
    self.pictureImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_pictureImageView];
    
    self.introduceWordsLabel = [[UILabel alloc] init];
    [self addSubview:_introduceWordsLabel];
    _introduceWordsLabel.numberOfLines = 0;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _pictureImageView.frame = CGRectMake(0, 0, self.frame.size.width, ([UIScreen mainScreen].bounds.size.width - 30) / 2 + 20);
    _pictureImageView.backgroundColor = [UIColor colorWithRed:0.498 green:0.498 blue:0.498 alpha:1.0];
    
    if ([self.videoCollectModel.describe isEqualToString:@""]) {
        _introduceWordsLabel.frame = CGRectZero;
    }else
    {
        _introduceWordsLabel.frame = CGRectMake(_pictureImageView.frame.origin.x + 5, _pictureImageView.frame.origin.y + _pictureImageView.frame.size.height + 10, _pictureImageView.frame.size.width - 10, [AutoadaptationFrame heightOfLabel:self.videoCollectModel.describe andTextFont:[UIFont systemFontOfSize:13] andLabelWidth:_pictureImageView.frame.size.width - 10]);
    }
}

- (void)setVideoCollectModel:(VideoCollectModel *)videoCollectModel
{
    if (_videoCollectModel != videoCollectModel) {
        [_videoCollectModel release];
        _videoCollectModel = [videoCollectModel retain];
    }
    [_pictureImageView sd_setImageWithURL:[NSURL URLWithString:videoCollectModel.posterPic]];
    
    _introduceWordsLabel.text = videoCollectModel.describe;
    _introduceWordsLabel.font = [UIFont systemFontOfSize:13];
    _introduceWordsLabel.textColor = [UIColor colorWithRed:0.5141 green:0.5141 blue:0.5141 alpha:1.0];
}

@end
